home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JPopupMenu$PanelPopup.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  3.7 KB  |  159 lines

  1. package javax.swing;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.BorderLayout;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Graphics;
  8. import java.awt.Panel;
  9. import java.awt.Point;
  10. import java.awt.Rectangle;
  11. import java.awt.Window;
  12. import java.io.Serializable;
  13.  
  14. class JPopupMenu$PanelPopup extends Panel implements JPopupMenu.Popup, Serializable {
  15.    // $FF: synthetic field
  16.    private final JPopupMenu this$0;
  17.    int desiredLocationX;
  18.    int desiredLocationY;
  19.    JRootPane rootPane;
  20.  
  21.    public JPopupMenu$PanelPopup(JPopupMenu var1) {
  22.       this.this$0 = var1;
  23.       ((Container)this).setLayout(new BorderLayout());
  24.       this.rootPane = new JRootPane();
  25.       ((Container)this).add(this.rootPane, "Center");
  26.    }
  27.  
  28.    public void addComponent(Component var1, Object var2) {
  29.       this.rootPane.getContentPane().add(var1, var2);
  30.    }
  31.  
  32.    Point convertParentLocationToScreen(Container var1, int var2, int var3) {
  33.       Window var4 = null;
  34.  
  35.       for(Object var6 = this; var6 != null; var6 = ((Component)var6).getParent()) {
  36.          if (var6 instanceof Window) {
  37.             var4 = (Window)var6;
  38.             break;
  39.          }
  40.       }
  41.  
  42.       if (var4 != null) {
  43.          Rectangle var5 = ((Component)var4).getBounds();
  44.          Point var7 = new Point(var2, var3);
  45.          var7 = SwingUtilities.convertPoint(var1, var7, (Component)null);
  46.          var7.x += var5.x;
  47.          var7.y += var5.y;
  48.          return var7;
  49.       } else {
  50.          throw new Error("convertParentLocationToScreen: no window ancestor found");
  51.       }
  52.    }
  53.  
  54.    Point convertScreenLocationToParent(Container var1, int var2, int var3) {
  55.       Window var4 = null;
  56.  
  57.       for(Container var6 = var1; var6 != null; var6 = ((Component)var6).getParent()) {
  58.          if (var6 instanceof Window) {
  59.             var4 = (Window)var6;
  60.             break;
  61.          }
  62.       }
  63.  
  64.       if (var4 != null) {
  65.          Point var7 = new Point(var2, var3);
  66.          SwingUtilities.convertPointFromScreen(var7, var1);
  67.          return var7;
  68.       } else {
  69.          throw new Error("convertScreenLocationToParent: no window ancestor found");
  70.       }
  71.    }
  72.  
  73.    public Rectangle getBoundsOnScreen() {
  74.       Container var1 = ((Component)this).getParent();
  75.       if (var1 != null) {
  76.          Rectangle var2 = ((Component)this).getBounds();
  77.          Point var3 = this.convertParentLocationToScreen(var1, var2.x, var2.y);
  78.          var2.x = var3.x;
  79.          var2.y = var3.y;
  80.          return var2;
  81.       } else {
  82.          throw new Error("getBoundsOnScreen called on an invisible popup");
  83.       }
  84.    }
  85.  
  86.    public Component getComponent() {
  87.       return this;
  88.    }
  89.  
  90.    public int getHeight() {
  91.       return ((Component)this).getBounds().height;
  92.    }
  93.  
  94.    public int getWidth() {
  95.       return ((Component)this).getBounds().width;
  96.    }
  97.  
  98.    public void hide() {
  99.       Container var1 = ((Component)this).getParent();
  100.       Rectangle var2 = ((Component)this).getBounds();
  101.       if (var1 != null) {
  102.          var1.remove(this);
  103.       }
  104.  
  105.       ((Component)var1).repaint(var2.x, var2.y, var2.width, var2.height);
  106.    }
  107.  
  108.    public void pack() {
  109.       ((Component)this).setSize(((Container)this).getPreferredSize());
  110.    }
  111.  
  112.    public void paint(Graphics var1) {
  113.       super.paint(var1);
  114.    }
  115.  
  116.    public void removeComponent(Component var1) {
  117.       this.rootPane.getContentPane().remove(var1);
  118.    }
  119.  
  120.    public void setLocationOnScreen(int var1, int var2) {
  121.       Container var3 = ((Component)this).getParent();
  122.       if (var3 != null) {
  123.          Point var4 = this.convertScreenLocationToParent(var3, var1, var2);
  124.          ((Component)this).setLocation(var4.x, var4.y);
  125.       } else {
  126.          this.desiredLocationX = var1;
  127.          this.desiredLocationY = var2;
  128.       }
  129.  
  130.    }
  131.  
  132.    public void show(Component var1) {
  133.       Container var2 = null;
  134.       if (var1 != null) {
  135.          var2 = var1.getParent();
  136.       }
  137.  
  138.       while(!(var2 instanceof Window) && !(var2 instanceof Applet) && var2 != null) {
  139.          var2 = ((Component)var2).getParent();
  140.       }
  141.  
  142.       if (var2 instanceof RootPaneContainer) {
  143.          JLayeredPane var4 = ((RootPaneContainer)var2).getLayeredPane();
  144.          Point var3 = this.convertScreenLocationToParent(var4, this.desiredLocationX, this.desiredLocationY);
  145.          ((Component)this).setLocation(var3.x, var3.y);
  146.          ((JLayeredPane)var4).add(this, JLayeredPane.POPUP_LAYER, 0);
  147.       } else {
  148.          Point var5 = this.convertScreenLocationToParent(var2, this.desiredLocationX, this.desiredLocationY);
  149.          ((Component)this).setLocation(var5.x, var5.y);
  150.          var2.add(this);
  151.       }
  152.  
  153.    }
  154.  
  155.    public void update(Graphics var1) {
  156.       this.paint(var1);
  157.    }
  158. }
  159.